package mmoon.mmoonstory.items;

import mmoon.mmoonstory.EasyCommand;
import mmoon.mmoonstory.interfaces.InitItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

public class ItemRainSummon extends Item implements InitItem {
    public static final String ObjID = "rain_summon";

    public ItemRainSummon() {
        super();
        this.setMaxStackSize(16);
        this.init(ObjID);
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
        if (!entity.world.isRemote) {
            entity.world.rainingStrength++;
            if (!player.isCreative()) {
                stack.shrink(1);
            }
            return true;
        }
        return false;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
        /* 右键扔出雪球 */
        if (world.isRemote) {
            return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
        }
        EasyCommand.makeSnowBall(player);
        ItemStack stack = player.getHeldItem(hand);
        if (!player.isCreative()) {
            stack.shrink(1);
        }
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
}
